/*
* @Author: syq
* @Date:   2017-12-05 10:54:36
* @Last Modified by:   shenyanqiu
* @Last Modified time: 2017-12-05 19:42:47
*/
import React from 'react'
import { Table,Button,Modal,Badge  } from 'antd';
import styles from './List.less'

const confirm = Modal.confirm;


class List extends React.Component {
  state = {
    selectedRowKeys: [], // Check here to configure the default column
  };
  onSelectChange = (selectedRowKeys) => {
    console.log('selectedRowKeys changed: ', selectedRowKeys);
    this.setState({ selectedRowKeys });
  }
  _getColumnConfig(){
    const { onSignTo } = this.props;
    const btnClickHandler = (record, handleType) => {
      handleType === 'sign' && confirm({
        title: '你确定要操作本条记录？',
        onOk() {
          onSignTo(record.id, record);
        },
      });
    };
    return [{
        title: '名字',
        dataIndex: 'name',
        key: 'name',
      }, {
        title: '部门',
        dataIndex: 'section',
        key: 'section',
        // render: () => <span><Badge status="success" />已通过</span>
      }, {
        title: '职位',
        dataIndex: 'job',
        key: 'job',
      }, {
        title: '联系方式',
        dataIndex: 'tel',
        key: 'tel',
      }, {
        title: '性别',
        dataIndex: 'sex',
        key: 'sex',
      }, {
          title: '操作',
          key: 'operation',
          width: 150,
          render: (text, record) => {
            return (<div className={styles.operationArea}>
              <Button type="primary" size={'small'} onClick={() => btnClickHandler(record, 'sign')}>标位离职</Button>
            </div>);
          },
      }];
  }
  render() {
    const { selectedRowKeys } = this.state;
    const { ...tableProps } = this.props;
    const rowSelection = {
      selectedRowKeys,
      onChange: this.onSelectChange,
      hideDefaultSelections: false,
      selections: [{
        key: '',
        text: ''
      }],
      onSelection: this.onSelection,
    };
    return (
      <Table
        {...tableProps}
        rowSelection={rowSelection}
        columns={this._getColumnConfig()}
        rowKey={record => record.id}
      />
    );
  }
}

export default List
